procedure DoFilter(type:integer); VAR i, picNo: integer; BEGIN picNo := PicNumber; SelectPic(picNo); SetOption; IF (nSlices < 2) then BEGIN if type = 1 then smooth; if type = 2 then sharpen; if type = 3 then reduceNoise; if type = 4 then Convolve('metzsharp'); END; IF (nSlices > 1) THEN BEGIN FOR i := 1 TO nSlices DO BEGIN ChooseSlice(i); if type = 1 then smooth; if type = 2 then sharpen; if type = 3 then reduceNoise; if type = 4 then Convolve('metzsharp'); END; SelectSlice(1); END; END; procedure DoRotate(direction:string); VAR i, N, picNo, pic2No, pic3No, width, height: integer; isTrue: Boolean; BEGIN picNo := PicNumber; isTrue := true; SelectPic(picNo); GetPicSize(width,height); SetNewSize(height,width); SetOption; IF (width = height) THEN BEGIN isTrue := false; END; N := nSlices; IF ( N < 2) THEN BEGIN if direction = 'L' then RotateLeft(isTrue); if direction = 'R' then RotateRight(isTrue); killRoi; ChoosePic(picNo); killRoi; END; IF (N > 1) THEN BEGIN FOR i := 1 TO N DO BEGIN IF ((isTrue = true) AND (i = 1)) THEN BEGIN MakeNewStack('Rotated'); pic2No:=PicNumber; END; ChoosePic(picNo); ChooseSlice(i); if direction = 'L' then RotateLeft(isTrue); if direction = 'R' then RotateRight(isTrue); IF (isTrue = true) THEN BEGIN pic3No := picNumber; ChoosePic(pic3No); SelectAll; Copy; Dispose; ChoosePic(pic2No); paste; IF ( i < N) THEN addSlice; IF ( i = N) THEN BEGIN ChoosePic(picNo); dispose; SelectPic(nPics); ChooseSlice(1); killRoi; END; END; END; END; END; PROCEDURE PlotHisto(frames:real); VAR xmin,xmax,ymin,ymax,min,max,xscale,yscale:real; i,MaxPlotWindowHeight:integer; PlotTop,PlotBottom,PlotWidth,PlotHeight:integer; hMargin,vMargin,SavePlotTop,PlotWindowSize:integer; PlotWinHeight,PlotWinWidth,PlotsPid:integer; sameCurve:string; BEGIN xmin:=0; xmax:=frames-1; ymin:=0; ymax:=0; sameCurve := 'n'; FOR i :=1 TO frames DO BEGIN IF rUser1[i] > ymax THEN ymax := rUser1[i]; END; PlotWidth:=256; PlotHeight:=128; xscale:=plotWidth/xmax; yscale:=plotHeight/ymax; MaxPlotWindowHeight:=800; hMargin:=35; vMargin:=5; PlotWinHeight:=PlotHeight+2*vMargin; PlotWinWidth:=PlotWidth+2*hMargin; PlotWindowSize:=PlotWinWidth*PlotWinHeight; SetForegroundColor(255); SetBackgroundColor(0); SetNewSize(PlotWinWidth,PlotWinHeight); MakeNewWindow('Time-Activity'); PlotsPid:=PidNumber; PlotTop:=vMargin; SetLineWidth(1); PlotBottom:=PlotTop+(ymax-ymin)*yscale; SelectPic(PlotsPid); MoveTo(hMargin,PlotBottom-(rUser1[1]-ymin)*yscale); for i:=1 to frames do LineTo(hMargin+i*xscale,PlotBottom-(rUser1[i]-ymin)*yscale); PlotTop:=PlotTop+PlotHeight; ResetCounter; SetOptions('Area'); WandAutoMeasure(true); AdjustAreas(true); LabelParticles(false); IncludeInteriorHoles(true); SetFontSize(10); IF sameCurve = 'n' THEN BEGIN SetText('Left Justified'); MoveTo(1,5); Write(ymax); MoveTo(1,60); Write('Cts'); MoveTo(1,127); Write('0'); MoveTo(20,127); Write('1'); MoveTo(145,127); Write('Frame'); MoveTo(290,127); Write(frames); END; IF sameCurve = 'y' THEN BEGIN SetText('Right Justified'); MoveTo(290,5); Write(ymax); MoveTo(305,60); Write('Cts'); MoveTo(305,127); Write('0'); END; END; macro '[A] Animate All'; VAR i, j, n, picNo: integer; BEGIN RequiresVersion(1.56); picNo := picNumber; IF (nslices < 2) THEN BEGIN PutMessage('Not all windows are stacks.'); EXIT; END; n := nSlices; FOR i := 1 to nPics DO BEGIN choosePic(i); IF (nslices < 2) THEN BEGIN PutMessage('Not all windows are stacks.'); EXIT; END; IF ((nSlices < n) OR (nSlices > n)) THEN BEGIN PutMessage('All open stacks must have the same number of slices'); EXIT; END; END; i:=0; repeat i:=i+1; if i>nSlices then i:=1; FOR j := 1 to nPics DO BEGIN choosePic(j); selectSlice(i); END; until button; end; macro '[B] Background subtraction'; VAR i, picNo, left, top, width, height, constant: integer; answer: string; BEGIN RequiresVersion(1.56); picNo := PicNumber; selectPic(picNo); GetRoi(left,top,width,height); IF width = 0 THEN BEGIN PutMessage('Draw an ROI then reselect'); EXIT; END; IF ( nSlices < 2) THEN BEGIN measure; constant := -1 * round(rMean[rCount]); selectAll; AddConstant(constant); killRoi; END; IF ( nSlices > 1) THEN BEGIN resetCounter; answer := 'undefined'; WHILE ((answer <> 'Y') AND (answer <> 'N')) DO BEGIN answer := getString('Frame by frame sub? (Y or N)',answer); END; IF answer = 'N' THEN BEGIN measure; constant := -1 * round(rMean[rCount]); FOR i := 1 TO nSlices DO BEGIN ChooseSlice(i); selectAll; AddConstant(constant); killRoi; END; END; IF answer = 'Y' THEN BEGIN FOR i := 1 TO nSlices DO BEGIN ChooseSlice(i); measure; END; FOR i := 1 TO nSlices DO BEGIN ChooseSlice(i); selectAll; AddConstant( -1 * round(rMean[i])); killRoi; END; END; chooseSlice(1); END; END; macro '[C] Crop images'; VAR i,OldStack,NewStack:integer; RoiLeft,RoiTop,RoiWidth,RoiHeight:integer; N:integer; BEGIN RequiresVersion(1.56); SaveState; OldStack:=PicNumber; GetRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight); IF (RoiWidth = 0) THEN BEGIN PutMessage('A rectangular ROI must be created'); EXIT; END; killRoi; N:=nSlices; SetNewSize(RoiWidth,RoiHeight); SetScaling('Bilinear; Create New Window'); SelectPic(OldStack); IF (N < 2) THEN BEGIN makeRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight); ScaleAndRotate(1,1,0); SelectPic(oldStack); killRoi; SelectPic(nPics); END; IF (N > 1) THEN BEGIN MakeNewStack('Stack'); NewStack:=PicNumber; FOR i:= 1 to N DO BEGIN choosePic(OldStack); chooseSlice(i); makeRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight); ScaleAndRotate(1,1,0); SelectAll; Copy; dispose; choosePic(NewStack); Paste; IF (i < N) THEN addSlice; END; ChoosePic(oldStack); killRoi; SelectPic(nPics); killRoi; selectSlice(1); END; RestoreState; END; macro '[E] Extract subgroup'; VAR i, firstFrame, lastFrame, picNo, newPicNo, width, height: integer; BEGIN RequiresVersion(1.56); picNo := PicNumber; SelectPic(picNo); firstFrame := 0; if (nSlices > 1) THEN BEGIN WHILE (firstFrame < 1) OR (firstFrame > nSlices) DO BEGIN firstFrame := Getnumber('Enter first frame of subGroup',firstFrame); END; WHILE (lastFrame < firstFrame+1) OR (lastFrame > nSlices) DO BEGIN lastFrame := Getnumber('Enter last frame of subGroup',nSlices); END; SelectAll; GetPicSize(width,height); killRoi; SetNewSize(width,height); SetOption; MakeNewStack('SubGroup'); newPicNo:=PicNumber; i := 1; WHILE (i < lastFrame - firstFrame + 2) DO BEGIN SelectPic(picNo); ChooseSlice(firstFrame); SelectAll; Copy; DeleteSlice; killRoi; ChoosePic(newPicNo); addSlice; paste; i := i + 1; END; ChooseSlice(1); DeleteSlice; killRoi; END; END; macro '[F] Filter Images'; VAR type: integer; BEGIN RequiresVersion(1.56); type := 0; WHILE (type < 1) OR (type > 4) DO BEGIN type := GetNumber('1-smooth 2-sharp 3-reduce 4-metz',type); DoFilter(type); END; END; macro '[G] Gray Scale'; BEGIN SetPalette('GrayScale'); END; macro '[H] Flip Horizontal'; VAR i, picNo: integer; BEGIN picNo := PicNumber; SelectPic(picNo); SetOption; IF ( nSlices < 2) THEN BEGIN FlipHorizontal; END; IF ( nSlices > 1) THEN BEGIN FOR i := 1 TO nSlices DO BEGIN ChooseSlice(i); FlipHorizontal; END; selectSlice(1); END; END; macro '[I] Invert LUT'; BEGIN InvertLUT; END; macro '[M] Multiply by Constant'; VAR i, picNo,constant: integer; BEGIN picNo := PicNumber; SelectPic(picNo); SetOption; constant := 2; constant := getNumber('Enter multiplication factor',constant); IF ( nSlices < 2) THEN BEGIN MultiplyByConstant(constant); END; IF ( nSlices > 1) THEN BEGIN FOR i := 1 TO nSlices DO BEGIN ChooseSlice(i); MultiplyByConstant(constant); END; selectSlice(1); END; END; macro '[O] Oblique Angulation'; VAR i,N,OldStack,NewStack: integer; RoiLeft,RoiTop,RoiWidth,RoiHeight: integer; angle: real; BEGIN SaveState; RequiresVersion(1.56); OldStack:=PicNumber; angle := -30; angle := getNumber('Enter angle to rotate',angle); selectAll; getRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight); killRoi; N:=nSlices; SetNewSize(RoiWidth,RoiHeight); SetScaling('Bilinear; Create New Window'); IF (N < 2) THEN BEGIN ScaleAndRotate(1,1,angle); killRoi; END; IF (N > 1) THEN BEGIN MakeNewStack('Stack'); NewStack:=PicNumber; FOR i:= 1 to N DO BEGIN choosePic(OldStack); chooseSlice(i); makeRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight); ScaleAndRotate(1,1,angle); SelectAll; Copy; dispose; choosePic(OldStack); killRoi; choosePic(NewStack); Paste; killRoi; IF (i < N) THEN addSlice; END; SelectPic(nPics); ChooseSlice(1); END; RestoreState; END; macro '[P] Back Projection'; VAR i, j, k, N, OldStack,NewStack, transPid, maxCts: integer; RoiLeft, RoiTop, RoiWidth, RoiHeight: integer; Left, Top, Width, Height, transaxials: integer; angle, start, scaleFactor: real; BEGIN SaveState; RequiresVersion(1.56); ChoosePic(nPics); OldStack:=nPics; N:=nSlices; IF (N < 2) THEN BEGIN PutMessage('The window is not a stack.'); EXIT; END; ResetCounter; maxCts := 0; start := -45; start := getNumber('Enter starting angle',start); angle := 180; angle := getNumber('Enter Length of arc',angle); angle := angle / nSlices; SetScaling('Bilinear; Same Window'); GetRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight); IF (RoiWidth = 0) THEN BEGIN selectAll; GetRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight); END; FOR i:= 1 to N DO BEGIN chooseSlice(i); Measure; if rMax[rCount] > maxCts THEN maxCts := rMax[rCount]; scaleFactor := 256 / maxCts; END; killroi; GetPicSize(Width,Height); SetNewSize(Width,Height); IF (N > 1) THEN BEGIN MakeNewStack('Transaxials'); transaxials:=PicNumber; transPid := pidNumber; MakeNewWindow('Projection'); NewStack:=PicNumber; FOR k:= RoiTop+1 TO RoiTop+RoiHeight-1 DO BEGIN FOR i:= 1 to N DO BEGIN tilewindows; ChoosePic(OldStack); ChooseSlice(i); MakeLineRoi(0,k,Width,k); copy; killroi; ChoosePic(NewStack); FOR j:= 0 TO Height-1 DO BEGIN MakeLineRoi(0,j,Width,j); Paste; killroi; END; MultiplyByConstant(scaleFactor); ScaleAndRotate(1,1,start + ((i-1) * angle)); MultiplyByConstant(1/i); ImageMath('add',transaxials,newStack,(i/(i+1)),0,transPid); END; if k < RoiTop + RoiHeight - 1 then addSlice; tilewindows; END; choosePic(nPics); dispose; RestoreState; END; END; macro '[R] Rotate Images'; VAR direction: string; BEGIN RequiresVersion(1.56); direction := 'undefined'; WHILE ((direction <> 'R') AND (direction <> 'L')) DO BEGIN direction := getString('R - right L - left',direction); END; DoRotate(direction); END; macro '[S] Shuffle images'; VAR i, j, heads, projections, picNo, width, height, newPicNo: integer; BEGIN RequiresVersion(1.56); picNo := PicNumber; SelectPic(picNo); if (nSlices > 1) THEN BEGIN heads := Getnumber('Enter increment to shuffle',2); projections := nSlices/heads; SelectAll; GetPicSize(width,height); killRoi; SetNewSize(width,height); SetOption; MakeNewStack('Shuffled'); newPicNo:=PicNumber; for i := 1 to heads do BEGIN for j := 1 to projections do BEGIN SelectPic(picNo); ChooseSlice((heads-i)*(j-1) + 1); SelectAll; Copy; if nSlices > 1 then DeleteSlice; ChoosePic(newPicNo); addSlice; paste; END; END; ChooseSlice(1); DeleteSlice; SelectPic(picNo); Dispose; SelectSlice(1); killRoi; END; END; macro '[T] Translate GE Star Images'; {Imports GE images into a stack.} VAR i,type,format,width,height,depth,nImages,hdrsize, maxPixel:integer; patientName,buffer, isTrue: String; BEGIN RequiresVersion(1.50); SetImport('8-bit'); SetCustom(1024,1,0); Import(''); {Read in header as an image, prompting for file name.} hdrSize := 1408; nImages := GetPixel(808,0); nImages := nImages + (GetPixel(809,0) * 256); depth := GetPixel(667,0); height := GetPixel(663,0); height := height + (GetPixel(664,0) * 256); width := GetPixel(665,0); width := width + (GetPixel(666,0) * 256); maxPixel := GetPixel(745,0); maxPixel := maxPixel + (GetPixel(746,0) * 256); patientName := ''; For i := 1 to 8 do BEGIN If (GetPixel(29 + i,0) > 32) Then BEGIN buffer := chr( GetPixel(29 + i,0) ); patientName := concat(patientName,buffer ); END; END; buffer := ' '; patientName := concat(patientName,buffer); For i := 1 to 7 do BEGIN If (GetPixel(1 + i,0) > 32) Then BEGIN buffer := chr( GetPixel(1 + i,0) ); patientName := concat(patientName,buffer ); END; END; buffer := ' '; patientName := concat(patientName,buffer); For i := 1 to 8 do BEGIN If (GetPixel(257+ i,0) > 32) Then BEGIN buffer := chr( GetPixel(257 + i,0) ); patientName := concat(patientName,buffer ); END; END; buffer := ' '; patientName := concat(patientName,buffer); For i := 1 to 6 do BEGIN If (GetPixel(385 + i,0) > 32) Then BEGIN buffer := chr( GetPixel(385 + i,0) ); patientName := concat(patientName,buffer ); END; END; Dispose; isTrue := 'undefined'; IF (depth = 2) AND (nImages > 1)THEN BEGIN WHILE ((isTrue <> 'N') AND (isTrue <> 'Y')) DO BEGIN isTrue := getString('Image-by-image scaling? (Y or N)','N'); END; END; If depth = 2 THEN BEGIN IF (isTrue = 'Y') OR (isTrue ='undefined') THEN SetImport('16-bit Unsigned, Swap Bytes'); IF (isTrue = 'N') THEN BEGIN maxPixel := Getnumber('Enter maximum pixel value',maxPixel); SetImportMinMax(0,maxPixel); SetImport('16-bit Unsigned, Swap Bytes, Fixed Scale'); END; END; If depth = 1 THEN BEGIN IF (maxPixel = 0) THEN BEGIN maxPixel := Getnumber('Enter maximum pixel value',maxPixel); END; SetImportMinMax(0,maxPixel); SetImport('8-bit, Fixed Scale'); END; SetCustom(width, height, HdrSize, nImages); Import(''); SelectAll; IF (nImages = 1) THEN BEGIN IF (depth = 2) THEN Invert; ChangeValues(0,1,1); ChangeValues(254,255,254); END; IF (nImages > 1) THEN BEGIN FOR i:= 1 to nImages DO BEGIN ChooseSlice(i); IF (depth = 2) THEN Invert; ChangeValues(0,1,1); ChangeValues(254,255,254); END; END; KillRoi; Beep; Beep; SetPicName(patientName); Save; END; macro '[V] Flip Vertical'; VAR i, picNo: integer; BEGIN picNo := PicNumber; SelectPic(picNo); SetOption; IF ( nSlices < 2) THEN BEGIN FlipVertical; END; IF ( nSlices > 1) THEN BEGIN FOR i := 1 TO nSlices DO BEGIN ChooseSlice(i); FlipVertical; END; selectSlice(1); END; END; macro '[Z] Zoom Images'; VAR i,N,OldStack,NewStack:integer; Width,Height:integer; zoomFactor: real; BEGIN RequiresVersion(1.56); SaveState; OldStack:=PicNumber; ChoosePic(OldStack); GetPicSize(Width,Height); N:=nSlices; zoomFactor := 0; WHILE (zoomFactor < 0.25) OR (zoomFactor > 4) DO BEGIN zoomFactor := GetNumber('Enter zoom factor',2); END; SetNewSize(Width*zoomFactor,Height*zoomFactor); SetScaling('Bilinear; Create New Window'); IF (N < 2) THEN BEGIN ScaleAndRotate(zoomFactor,zoomFactor,0); SelectPic(oldStack); dispose; SelectPic(nPics); END; IF (N > 1) THEN BEGIN chooseSlice(1); MakeNewStack('Stack'); NewStack:=PicNumber; FOR i:= 1 to N DO BEGIN choosePic(OldStack); chooseSlice(1); ScaleAndRotate(zoomFactor,zoomFactor,0); SelectAll; Copy; dispose; choosePic(NewStack); Paste; killRoi; choosePic(OldStack); deleteSlice; choosePic(NewStack); IF (i < N) THEN addSlice; IF (i = N) THEN BEGIN choosePic(OldStack); dispose; SelectPic(nPics); chooseSlice(1); END; END; END; RestoreState; END; macro ' '; BEGIN END; macro 'Truncate Range'; VAR i, picNo: integer; BEGIN picNo := PicNumber; SelectPic(picNo); SetOption; SelectAll; IF ( nSlices < 2) THEN BEGIN ChangeValues(0,1,1); ChangeValues(254,255,254); END; IF ( nSlices > 1) THEN BEGIN FOR i := 1 TO nSlices DO BEGIN ChooseSlice(i); ChangeValues(0,1,1); ChangeValues(254,255,254); END; selectSlice(1); END; KillRoi; END; macro ' '; BEGIN END; macro 'Generate Time-Activity Curve'; VAR i, picNo, frameED, frameES, frames, left, top, width, height: integer; LVEDV, LVESV: real; doLVEF: string; BEGIN RequiresVersion(1.56); picNo := PicNumber; frames := nslices; IF (nslices < 2) THEN BEGIN PutMessage('Not all windows are stacks.'); EXIT; END; GetRoi(left,top,width,height); IF width = 0 THEN BEGIN PutMessage('Draw an ROI then reselect'); EXIT; END; LVEDV := 0; LVESV := 9999999; frameED := 1; frameES := frames; ResetCounter; FOR i:= 1 to frames do BEGIN rUser1[i] :=0; END; FOR i:= 1 to frames do BEGIN ChoosePic(picNo); ChooseSlice(i); Measure; rUser1[i] := round( rMean[rCount]*rArea[rCount]); if (LVEDV < ( rMean[rCount]*rArea[rCount] ) ) then BEGIN LVEDV := rMean[rCount]*rArea[rCount]; frameED := i; END; if (LVESV > ( rMean[rCount]*rArea[rCount] ) ) then BEGIN LVESV := rMean[rCount]*rArea[rCount]; frameES := i; END; END; PlotHisto(frames); doLVEF := 'undefined'; WHILE ((doLVEF <> 'N') AND (doLVEF <> 'Y')) DO BEGIN doLVEF := GetString( 'Calculate LVEF? (Y or N)',doLVEF ); END; IF doLVEF = 'N' THEN EXIT; NewTextWindow('Analysis'); SelectWindow('Analysis'); Writeln( ' ' ); Writeln( ' ' ); Writeln( ' ' ); Writeln( ' ' ); Writeln( ' ' ); Writeln( ' ' ); Writeln( ' ' ); Writeln( ' ' ); Writeln( ' ' ); Writeln( ' ' ); Writeln( ' ' ); Writeln( ' ' ); Writeln( 'Max counts in Frame ', frameED ); Writeln( 'Min counts in Frame ', frameES ); Writeln( ' ' ); Writeln( ' ' ); Writeln( 'Draw End-diastole ( ED )' ); Writeln( 'Draw End-systole ( ES )' ); Writeln( 'Draw Background ( BKG )' ); Writeln( ' ' ); Writeln( 'Proceed to "Calculate LVEF..."' ); selectPic(picNo); chooseSlice(frameED); SelectAll; Copy; MoveWindow(100,40); SetNewSize(128,128); MakeNewWindow('ED'); SelectWindow('ED'); Paste; MoveWindow(410,40); ScaleSelection(2.00, 2.00); selectPic(picNo); chooseSlice(frameES); SelectAll; Copy; MakeNewWindow('ES'); SelectWindow('ES'); Paste; MoveWindow(410,190); ScaleSelection(2.00, 2.00); MakeNewWindow('BKG'); SelectWindow('BKG'); Paste; MoveWindow(410,340); ScaleSelection(2.00, 2.00); selectPic(picNo); chooseSlice(1); killRoi; MoveWindow(340,340); SelectWindow('Time-Activity'); SelectWindow('BKG'); SelectWindow('ES'); SelectWindow('ED'); END; macro ' '; BEGIN END; macro 'Calculate LVEF'; VAR LVEDV, LVESV, BKG, LVEF: real; pixelsED, pixelsES, ED: integer; BEGIN RequiresVersion(1.56); if nPics< 5 then begin PutMessage('Start with: Generate Time-Activity Curve'); exit; end; SelectWindow('ED'); Measure; pixelsED := 0.25 * rArea[rCount]; LVEDV := rMean[rCount]; SelectWindow('ES'); Measure; pixelsES := 0.25 * rArea[rCount]; LVESV := rMean[rCount]; SelectWindow('BKG'); Measure; BKG := rMean[rCount]; SelectWindow('Analysis'); Writeln( ' ' ); Writeln( 'ED pixels = ', round(pixelsED)); Writeln( 'ED mean Counts = ', LVEDV); Writeln( 'ES pixels = ', round(pixelsES)); Writeln( 'ES mean Counts = ', LVESV); Writeln( 'BKG mean Counts = ', BKG); LVEDV := (LVEDV - BKG) * pixelsED; LVESV := (LVESV - BKG) * pixelsES; LVEF := 100 * (LVEDV - LVESV) / LVEDV; Writeln( ' ' ); Writeln('LVEDV = ', round(LVEDV) ' counts'); Writeln('LVESV = ',round( LVESV) ' counts'); Writeln( ' ' ); Writeln('LVEF = ', round(LVEF) ' %'); SelectWindow('Time-Activity'); SelectWindow('BKG'); SelectWindow('ES'); SelectWindow('ED'); END; macro ' '; BEGIN END; procedure DoReslicing(horizontal:boolean); VAR stack1,stack2,width,height:integer; RoiLeft,RoiTop,RoiWidth,RoiHeight,max:integer; InputSpacing,OutputSpacing,loc:real; FirstTime:boolean; BEGIN RequiresVersion(1.56); if nPics=0 then begin PutMessage('This macro requires a stack.'); exit; end; if nSlices=0 then begin PutMessage('This window is not a stack.'); exit end; GetRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight); IF RoiWidth = 0 THEN BEGIN selectAll; GetRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight); END; SaveState; SetBackground(0); SetBackground(255); stack1:=PicNumber; InputSpacing:=GetSliceSpacing; if InputSpacing<=0 then InputSpacing:=1; InputSpacing:=GetNumber('Input Slice Spacing(Pixels):',InputSpacing); SetSliceSpacing(InputSpacing); OutputSpacing:=InputSpacing; OutputSpacing:=GetNumber('Output Slice Spacing (Pixels):', OutputSpacing); FirstTime:=true; GetRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight); if horizontal then begin loc:=RoiTop+OutputSpacing; max:=RoiTop+RoiHeight; end else begin loc:=RoiLeft+OutputSpacing; max:=RoiLeft+RoiWidth; end; while loc 1) THEN BEGIN FOR i := 1 TO nSlices DO BEGIN ChooseSlice(i); Invert; END; selectSlice(1); END; END; macro 'Reverse Sequence'; VAR i, projections, picNo, width, height, newPicNo: integer; BEGIN picNo := PicNumber; SelectPic(picNo); projections := nSlices; SelectAll; GetPicSize(width,height); killRoi; SetNewSize(width,height); SetOption; if (nSlices > 1) THEN BEGIN MakeNewStack('Shuffled'); newPicNo:=PicNumber; for i := 1 to projections do BEGIN SelectPic(picNo); ChooseSlice(projections+1-i); SelectAll; Copy; if nSlices > 1 then DeleteSlice; ChoosePic(newPicNo); addSlice; paste; END; ChooseSlice(1); DeleteSlice; SelectPic(picNo); Dispose; SelectSlice(1); killRoi; END; END; Macro '[S] Set Slice Spacing'; VAR defaultSpacing, spacing: real; BEGIN defaultSpacing := GetSliceSpacing; spacing := 0; WHILE ((spacing <0.1) OR (spacing > 8)) DO spacing := GetNumber('Enter slice spacing [in pixels]:',defaultSpacing); SetSliceSpacing(spacing); END; macro 'Sort CTI Whole body PET images'; VAR i, j, beds, picNo, width, height, newPicNo: integer; theSpacing: real; BEGIN picNo := PicNumber; theSpacing := GetSliceSpacing; SetOption; if (nSlices > 1) THEN BEGIN beds := trunc(nSlices/31); SelectAll; GetPicSize(width,height); SetNewSize(width,height); MakeNewStack('Shuffled'); newPicNo:=PicNumber; SetSliceSpacing(theSpacing); for i := 1 to beds do BEGIN for j := 1 TO 31 do BEGIN ChoosePic(picNo); ChooseSlice(32-j); SelectAll; Copy; DeleteSlice; ChoosePic(newPicNo); IF ((j > 2) AND (j < 30)) THEN BEGIN paste; addSlice; END; END; END; DeleteSlice; SelectPic(picNo); Dispose; SelectSlice(1); killRoi; END; END; macro 'Dispose all...'; VAR i: integer; BEGIN FOR i := 1 to nPics DO BEGIN choosePic(1); dispose; END; END;